package com.example.test.view;

import android.content.Intent;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.test.R;
import com.example.test.libshoppingcart.ShoppingCart;
import com.example.test.libshoppingcart.core.ShoppingCartManager;

public class ShoppingCart extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_shoppingcart);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        //加载封面图片
        ShoppingCart.setLoadCoverImpl((iv, goods) -> {
            //todo 加载封面图片

        });

        //选择购物车中的商品 点击事件
        ShoppingCartManager.getInstance().setOnItemViewClickListener(goods -> android.util.Log.d("goods", "###goods:" + goods));

        //添加商品到购物车
        findViewById(R.id.tvAddToCart).setOnClickListener(v -> ShoppingCartManager.getInstance().addToCart(new ShoppingCartManager.ShoppingCartGoods().setId("test").setName("test").setPrice("62.3").setCoverUrl("").setQuantity(1).setGoodsSize("重量 : 100G")));

        //启动购物车界面
        findViewById(R.id.tv).setOnClickListener(v -> startActivity(new Intent(ShoppingCart.this, ShoppingCart.class)));
    }
}
